package com.linln.wtp.controller.integralorder;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.linln.common.utils.SessionUtil;
import com.linln.common.vo.JsonResult;
import com.linln.common.vo.PageResult;
import com.linln.component.wtpshiro.annotation.UserLoginToken;
import com.linln.modules.integralmall.domain.IntegralMallService;
import com.linln.modules.order.domain.Order;
import com.linln.modules.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.wtp.integralorder
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.wtp.integralorder
 * @Description: TODO
 * @date Date : 2020年12月27日 17:07
 */
@RestController
@RequestMapping("integralOrder")
public class IntegralOrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 获取积分订单列表
     * @param pageNum 页码
     * @param limit 条数
     * @param status 状态
     * @return
     */
    @GetMapping
    @UserLoginToken
    public Map<String, Object> getIntegralOrderList(@RequestParam(required = false, defaultValue = "0", value = "pageNum") Integer pageNum, @RequestParam(required = false, defaultValue = "10") Integer limit, Integer status) {
        Map<String, Object> order = orderService.getIntegralMallOrder(pageNum, limit, SessionUtil.getUserId(), status);
        order.put("code", 200);
        return order;
    }

    @GetMapping("/info")
    @UserLoginToken
    public Map<String, Object> getIntegralOrderInfo(String orderId) {
        Map<String, Object> map = new HashMap<>();
        Order order = orderService.getIntegralMallOrderInfo(orderId);
        map.put("data", new HashMap<String,Object>(){{put("orderInfo",order);}});
        map.put("code", 200);
        return map;
    }


    @DeleteMapping
    @UserLoginToken
    public JsonResult delIntegralOrder(String orderId) {
        return orderService.delOrderById(orderId) ? JsonResult.ok("删除成功") : JsonResult.error("删除失败");
    }

}
